<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {


   public function index(){
        $id=$_GET['id'];
        $asyntask=M('asyntask');
        $data=$asyntask->alias('a')->join("__TASK__  b ON a.task_id=b.id")->where(['a.id'=>$id])->find();
        $de_json=json_decode($data['sort'],true);
       $arr=[];
        foreach ($de_json as $key => $value) {
            $arr[$key]=$value;
        }

         //发送通知
        require_once APP_PATH . "Common/Lib/push/sdk.php";
        $message = array(
            // 消息的标题.
            'title' => '有一个新任务，请注意查看',
            // 消息内容
            'description' => "运输：" . $data['task_from'] . '到' . $data['task_end'] . $data['total_load'] . '方',
            "custom_content"=> array("type"=>"1",'task_id'=>$id)
        );
        // 设置消息类型为 通知类型.
        $opts = array(
            'msg_type' => 1
        );
        
        // 创建SDK对象.
        $sdk = new \PushSDK();
        // 向目标设备发送一条消息
        $rs = $sdk->pushMsgToSingleDevice($arr[0]['channel_id'], $message, $opts);
        array_shift($arr);
        $asyntask->where(['id'=>$id])->save(['sort'=>json_encode($arr)]);
    }
    public function detail(){
        $id = I('get.id');
        $news_db = M('news');
        $this->news = $news_db->where('id='.$id)->find();
        $this->display();
    }

    public function page(){
        $id = I('get.id');
        $page_db = M('page');
        $this->page = $page_db->where('catid='.$id)->find();
        $this->display();
    }

    /**
     * 路况信息
     */
    public function roadpage(){
        $id = I('get.id');
        $feedback_db = M('feedback');
        $feedback = $feedback_db->where('id='.$id)->find();
        $feedback['imgs']= explode('|',$feedback['imgs']);
        $this->assign('feedback',$feedback);
        $this->display();
    }

}